//
//  DBHelp.m
//  DBClub_IOS
//
//  Created by 刘世财 on 15/1/26.
//  Copyright (c) 2015年 搭伴科技. All rights reserved.
//
#import "Header.h"
//#import "APPVersionCheck.h"
#import "DBHelper.h"
#import "CommonCrypto/CommonDigest.h"

static id _instance;

@interface DBHelper()<UIAlertViewDelegate>

@property(nonatomic,retain) NSString *APPStoreURL;

@end

@implementation DBHelper

+ (instancetype)sharedAppHelper
{
    @synchronized(self) {
        if (!_instance) {
            _instance = [[self alloc] init];
        }
    }
    return _instance;
}


/**
 * 图片压缩到指定大小
 * @param targetSize 目标图片的大小
 * @param sourceImage 源图片
 * @return 目标图片
 */
+ (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize withSourceImage:(UIImage *)sourceImage
{
    UIImage *newImage = nil;
    CGSize imageSize = sourceImage.size;
    CGFloat width = imageSize.width;
    CGFloat height = imageSize.height;
    CGFloat targetWidth = targetSize.width;
    CGFloat targetHeight = targetSize.height;
    CGFloat scaleFactor = 0.0;
    CGFloat scaledWidth = targetWidth;
    CGFloat scaledHeight = targetHeight;
    CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
    if (CGSizeEqualToSize(imageSize, targetSize) == NO)
    {
        CGFloat widthFactor = targetWidth / width;
        CGFloat heightFactor = targetHeight / height;
        if (widthFactor > heightFactor)
            scaleFactor = widthFactor; // scale to fit height
        else
            scaleFactor = heightFactor; // scale to fit width
        scaledWidth= width * scaleFactor;
        scaledHeight = height * scaleFactor;
        // center the image
        if (widthFactor > heightFactor)
        {
            thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
        }
        else if (widthFactor < heightFactor)
        {
            thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
        }
    }
    UIGraphicsBeginImageContext(targetSize); // this will crop
    CGRect thumbnailRect = CGRectZero;
    thumbnailRect.origin = thumbnailPoint;
    thumbnailRect.size.width= scaledWidth;
    thumbnailRect.size.height = scaledHeight;
    
    [sourceImage drawInRect:thumbnailRect];
    newImage = UIGraphicsGetImageFromCurrentImageContext();
    if(newImage == nil)
        NSLog(@"could not scale image");
    
    //pop the context to get back to the default
    UIGraphicsEndImageContext();
    
    return newImage;
}
//等比缩小
+(UIImage *) imageWithImagePaperSimple:(UIImage*)image NScale:(float) nScale  maxW:(float)max{
    //计算当前的应该显示的宽度宽度
    float maxW_curremt = image.size.width *nScale;
    float maxH_curremt = image.size.height *nScale;
    
    if (maxW_curremt > max) {
        maxW_curremt = max;
        maxH_curremt = maxW_curremt *image.size.height /image.size.width;
    }
    
    
    /*获取当前屏幕的比例*/  //一个点的像素
    float scale = [UIScreen mainScreen].scale;
    //opaque  :alpha通道  Yes:不透明/NO 透明  一般用NO  清晰
    /*开启位图上下文*/
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(maxW_curremt, maxH_curremt), NO, scale);
    //    UIGraphicsBeginImageContext(newSize);  //size 为CGSize类型，即你所需要的图片尺寸
    
    [image drawInRect:CGRectMake(0, 0, maxW_curremt, maxH_curremt)];
    
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    
    /*结束位图编辑*/
    UIGraphicsEndImageContext();
    
    return scaledImage;   //返回的就是已经改变的图片
}
//修发图片大小
+(UIImage *) imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize) newSize{
    newSize.height=image.size.height*(newSize.width/image.size.width);
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return  newImage;
}



+(NSString *)deviceIPAdress{
    NSString *address = @"an error occurred when obtaining ip address";
    struct ifaddrs *interfaces = NULL;
    struct ifaddrs *temp_addr = NULL;
    int success = 0;
    
    success = getifaddrs(&interfaces);
    
    if (success == 0) { // 0 表示获取成功
        
        temp_addr = interfaces;
        while (temp_addr != NULL) {
            if( temp_addr->ifa_addr->sa_family == AF_INET) {
                // Check if interface is en0 which is the wifi connection on the iPhone
                if ([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
                    // Get NSString from C String
                    address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
                }
            }
            
            temp_addr = temp_addr->ifa_next;
        }
    }
    
    freeifaddrs(interfaces);
    
    return address;
    
}

+ (NSString *)sha1:(NSString *)input
{
    const char *ptr = [input UTF8String];
    
    int i =0;
    int len = (int)strlen(ptr);
    Byte byteArray[len];
    while (i!=len)
    {
        unsigned eachChar = *(ptr + i);
        unsigned low8Bits = eachChar & 0xFF;
        
        byteArray[i] = low8Bits;
        i++;
    }
    
    unsigned char digest[CC_SHA1_DIGEST_LENGTH];
    
    CC_SHA1(byteArray, len, digest);
    
    NSMutableString *hex = [NSMutableString string];
    for (int i=0; i<20; i++)
    [hex appendFormat:@"%02x", digest[i]];
    
    NSString *immutableHex = [NSString stringWithString:hex];
    
    return immutableHex;
}


+(void)showMessage:(NSString *)message
{
    
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    UIView *showview = [[UIView alloc]init];
    showview.backgroundColor = [UIColor blackColor];
    showview.frame = CGRectMake(1, 1, 1, 1);
    showview.alpha = 1.0f;
    showview.layer.cornerRadius = 5.0f;
    showview.layer.masksToBounds = YES;
    [window addSubview:showview];

    UILabel *label = [[UILabel alloc]init];
//    NSDictionary *attributes = @{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:15]};
    
//    CGSize LabelSize = [message boundingRectWithSize:CGSizeMake(kScreenWidth-20, MAXFLOAT)
//                                              options:NSStringDrawingUsesDeviceMetrics
//                                           attributes:attributes
//                                              context:nil].size;
    label.text = message;
    label.textColor = [UIColor whiteColor];
    label.textAlignment = 1;
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:15];
    CGSize size = [label sizeThatFits:CGSizeMake(Main_Screen_Width-20, MAXFLOAT)];
    
//    NSLog(@"LabelSize W == %f",LabelSize.width);
    
    label.frame = CGRectMake(10, 5, size.width, size.height);
    
    
    [showview addSubview:label];
    showview.frame = CGRectMake((Main_Screen_Width - size.width - 20)/2, Main_Screen_Height- 100, size.width+20, size.height+10);
    [UIView animateWithDuration:2 animations:^{
        showview.alpha = 0;
    } completion:^(BOOL finished) {
        [showview removeFromSuperview];
        }];
}



void TTAlertNoTitle(NSString* message) {
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:message
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

//#pragma mark 首次打开APP检测版本信息
//-(void)didFinishLaunchcheckVersionNotes
//{
//#define APPIdentifier  @";ll;"
//    [APPVersionCheck isAppVersionUpdatedWithAppIdentifier:APPIdentifier updatedInformation:^(NSString *releaseNoteText, NSString *releaseVersionText, NSDictionary *resultDic) {
//        
//        [DBHelper showMessage:[NSString stringWithFormat:@"已更新版本:%@", releaseVersionText]];
//        
//    } latestVersionInformation:^(NSString *releaseNoteText, NSString *releaseVersionText, NSDictionary *resultDic) {
//        UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"有新版本:%@", releaseVersionText] message:releaseNoteText delegate:self cancelButtonTitle:@"忽略" otherButtonTitles: @"进行下载", @"下次再说",nil];
//        _APPStoreURL = [resultDic objectForKey:@"trackViewUrl"];
//        createUserResponseAlert.tag = 1102;
//        [createUserResponseAlert show];
//    } completionBlockError:^(NSError *error) {
//        NSLog(@"An error occurred: %@", [error localizedDescription]);
//    }];
//}

//#pragma mark 检测版本信息
//-(void)checkVersionNotes
//{
//    [APPVersionCheck isOrNotTheLatestVersionInformationWithAppIdentifier:APPIdentifier isOrNotTheLatestVersionCompletionBlock:^(BOOL isLatestVersion, NSString *releaseNoteText, NSString *releaseVersionText, NSDictionary *resultDic) {
//        if (isLatestVersion) {
//            [DBHelper showMessage:@"亲 已是最新版本"];
//        }else{
//            UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"有新版本:%@", releaseVersionText] message:releaseNoteText delegate:self cancelButtonTitle:@"忽略" otherButtonTitles: @"进行下载", @"下次再说",nil];
//            _APPStoreURL = [resultDic objectForKey:@"trackViewUrl"];
//            createUserResponseAlert.tag = 1102;
//            [createUserResponseAlert show];
//        }
//    } completionBlockError:^(NSError *error) {
//        NSLog(@"An error occurred: %@", [error localizedDescription]);
//    }];
//}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag == 1102) {
        switch (buttonIndex) {
            case 1:
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:_APPStoreURL]];
                break;
                
            default:
                break;
        }
    }
}

#pragma mark - 验证手机号码和电话号码的正则表达式
+ (BOOL)isValidateTel:(NSString *)tel
{
    //电话号码正则表达式（支持手机号码，3-4位区号，7-8位直播号码，1－4位分机号）
    NSString *regex = @"((\\d{11})|^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$)";
    //NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(177)|(18[0-9]))\\d{8}$";
    NSPredicate *telTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",regex];
    return [telTest evaluateWithObject:tel];
}

#pragma mark -验证密码 6~16位数字或字母
+ (BOOL) validatePWD: (NSString *) candidate {
    if (candidate.length < 6||candidate.length > 16) {
        return NO;
    }
    NSString *pwdRegex = @"^[a-zA-Z0-9]{6,50}$";
    NSPredicate *pwdTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pwdRegex];
    
    return [pwdTest evaluateWithObject:candidate];
}

#pragma mark 检测是否为中文
+ (BOOL) validateChinese:(NSString *)str
{
    NSString *pwdRegex = @"^[\u4E00-\u9FA5]*$";
    NSPredicate *pwdTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pwdRegex];
    
    return [pwdTest evaluateWithObject:str];
}


+(NSString *) md5: (NSString *) inPutText
{
    const char *cStr = [inPutText UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(cStr, (int)strlen(cStr), result);
    
    return [[NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
             result[0], result[1], result[2], result[3],
             result[4], result[5], result[6], result[7],
             result[8], result[9], result[10], result[11],
             result[12], result[13], result[14], result[15]
             ] lowercaseString];
}

+(NSString *)getTimeWithDate:(NSString *)date
{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSDate * d = [dateFormatter dateFromString:date];
    
    NSTimeInterval late = [d timeIntervalSince1970]*1;
    
    NSString * timeString = nil;
    
    NSDate * dat = [NSDate dateWithTimeIntervalSinceNow:0];
    
    NSTimeInterval now = [dat timeIntervalSince1970]*1;
    
    NSTimeInterval cha = now - late;
    if (cha/3600 < 1) {
        
        timeString = [NSString stringWithFormat:@"%f", cha/60];
        
        timeString = [timeString substringToIndex:timeString.length-7];
        
        int num= [timeString intValue];
        
        if (num <= 1) {
            
            timeString = [NSString stringWithFormat:@"刚刚"];
            
        }else{
            
            timeString = [NSString stringWithFormat:@"%@分钟前", timeString];
            
        }
        
    }
    
    if (cha/3600 > 1 && cha/86400 < 1) {
        
        timeString = [NSString stringWithFormat:@"%f", cha/3600];
        
        timeString = [timeString substringToIndex:timeString.length-7];
        
        timeString = [NSString stringWithFormat:@"%@小时前", timeString];
        
    }
    
    
    if (cha/86400 > 1)
        
    {
        NSTimeInterval secondPerDay = 24*60*60;
        
        NSDate * yesterDay = [NSDate dateWithTimeIntervalSinceNow:-secondPerDay];
        
        NSDate * beforeYesterDay = [NSDate dateWithTimeIntervalSinceNow:-2*secondPerDay];
        
        NSCalendar * calendar = [NSCalendar currentCalendar];
        
        unsigned uintFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
        
        NSDateComponents * souretime = [calendar components:uintFlags fromDate:d];
        
        NSDateComponents * yesterday = [calendar components:uintFlags fromDate:yesterDay];
        
        NSDateComponents *beforeYesterDay_ = [calendar components:uintFlags fromDate:beforeYesterDay];
        
        if (souretime.year == yesterday.year && souretime.month == yesterday.month && souretime.day == yesterday.day){
            
            [dateFormatter setDateFormat:@"HH:mm"];
            
            timeString = [NSString stringWithFormat:@"昨天 %@  ",[dateFormatter stringFromDate:d]];
        }
        else if(souretime.year == beforeYesterDay_.year && souretime.month == beforeYesterDay_.month && souretime.day == beforeYesterDay_.day)
        {
            [dateFormatter setDateFormat:@"HH:mm"];
            
            timeString = [NSString stringWithFormat:@"前天 %@  ",[dateFormatter stringFromDate:d]];
        }
        else
        {
            int num = cha/84600;
            
            [dateFormatter setDateFormat:@"HH:mm"];
            
            NSLog(@"num num num num == %d",num);
            
            timeString = [NSString stringWithFormat:@"%d天前 %@  ",num,[dateFormatter stringFromDate:d]];
            
        }
    }
    
    return timeString;
}

/**
 *  通过日期求星期
 *
 *  @param date <#date description#>
 *
 *  @return 日期字符串
 */
+ (NSString*)fromDateToWeek:(NSDate*)date
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyyMMdd"];
    NSString *selectDate = [dateFormatter stringFromDate:date];
    NSInteger yearInt = [selectDate substringWithRange:NSMakeRange(0, 4)].integerValue;
    NSInteger monthInt = [selectDate substringWithRange:NSMakeRange(4, 2)].integerValue;
    NSInteger dayInt = [selectDate substringWithRange:NSMakeRange(6, 2)].integerValue;
    int c = 20;//世纪
    int y = (int)yearInt -1;//年
    int d = (int)dayInt;
    int m = (int)monthInt;
    int w =(y+(y/4)+(c/4)-2*c+(26*(m+1)/10)+d-1)%7;
    NSString *weekDay = @"";
    switch (w) {
        case 0:
            weekDay = @"星期日";
            break;
        case 1:
            weekDay = @"星期一";
            break;
        case 2:
            weekDay = @"星期二";
            break;
        case 3:
            weekDay = @"星期三";
            break;
        case 4:
            weekDay = @"星期四";
            break;
        case 5:
            weekDay = @"星期五";
            break;
        case 6:
            weekDay = @"星期六";
            break;
        default:
            break;
    }
    return weekDay;
}

/**
 *  获取当前的时间信息
 *
 *  @return <#return value description#>
 */
+(NSDictionary *) getTimeInfo:(NSDate *)date
{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:date];
    
    int year = (int)[dateComponent year];
    int month = (int)[dateComponent month];
    int day = (int)[dateComponent day];
    int hour = (int)[dateComponent hour];
    int minute = (int)[dateComponent minute];
    int second = (int)[dateComponent second];
    // 获取星期几
    NSString *weekStr = [DBHelper fromDateToWeek:date];
    NSString *week = [weekStr substringWithRange:NSMakeRange(2, 1)];
    NSDictionary *dict = @{@"year":[NSString stringWithFormat:@"%d",year],
                           @"month":[NSString stringWithFormat:@"%d",month],
                           @"day":[NSString stringWithFormat:@"%d",day],
                           @"hour":[NSString stringWithFormat:@"%d",hour],
                           @"minute":[NSString stringWithFormat:@"%d",minute],
                           @"second":[NSString stringWithFormat:@"%d",second],
                           @"week":[NSString stringWithFormat:@"%@",week]};
    
    return dict;
}




//适配按比例计算控件大小和位置
+(CGRect)setFrameWith:(CGRect)RectMake
{
    float autoSizeScaleX;
    float autoSizeScaleY;
    
    if(Main_Screen_Height > 480){
        autoSizeScaleX = Main_Screen_Width/320;
        autoSizeScaleY = Main_Screen_Height/568;
    }else{
        autoSizeScaleX = 1.0;
        autoSizeScaleY = 1.0;
    }
    
    CGRect rect;
    rect.origin.x = RectMake.origin.x * autoSizeScaleX;
    rect.origin.y = RectMake.origin.y * autoSizeScaleY;
    
    rect.size.width = RectMake.size.width * autoSizeScaleX;
    rect.size.height = RectMake.size.height * autoSizeScaleY;
    
    return rect;
}

+(CGSize)setSizeWith:(CGSize)sizeMake
{
    float autoSizeScaleX;
    float autoSizeScaleY;
    
    if(Main_Screen_Height > 480){
        autoSizeScaleX = Main_Screen_Width/320;
        autoSizeScaleY = Main_Screen_Height/568;
    }else{
        autoSizeScaleX = 1.0;
        autoSizeScaleY = 1.0;
    }
    
    CGSize size;
    size.width = sizeMake.width * autoSizeScaleX;
    size.height = sizeMake.height * autoSizeScaleY;
    
    return size;
}

+(CGFloat)setAutoY:(CGFloat )y
{
    float autoSizeScaleY;
    
    if(Main_Screen_Height > 480){
        autoSizeScaleY = Main_Screen_Height/568;
    }else{
        autoSizeScaleY = 1.0;
    }
    
    return y*autoSizeScaleY;
}

+(CGFloat)setAutoX:(CGFloat )x
{
    float autoSizeScaleX;
    
    if(Main_Screen_Height > 480){
        autoSizeScaleX = Main_Screen_Height/320;
    }else{
        autoSizeScaleX = 1.0;
    }
    
    return x*autoSizeScaleX;
}

+(CGFloat)setAutoHeight:(CGFloat)height
{
    float autoSizeScaleY;
    
    if(Main_Screen_Height > 480){
        autoSizeScaleY = Main_Screen_Height/568;
    }else{
        autoSizeScaleY = 1.0;
    }
    
    return height*autoSizeScaleY;
    
}

+(CGFloat)setAutoWidth:(CGFloat)width
{
    float autoSizeScaleY;

    if(Main_Screen_Height > 480){
        autoSizeScaleY = Main_Screen_Height/568;
    }else{
        autoSizeScaleY = 1.0;
    }
    
    return width*autoSizeScaleY;
    
}

#pragma mark -自定义字符串转化为时间//yyyy-MM-dd HH:mm:ss
+ (NSDate*)dateFromCustomString:(NSString*)str format:(NSString*)formatStr{
    NSDateFormatter *format = [[NSDateFormatter alloc]init];
    [format setDateFormat:formatStr];
    return [format dateFromString:str];
}
#pragma mark -时间转化为自定义字符串
+ (NSString*)stringFromCustomFormatDate:(NSDate*)date format:(NSString*)formatStr{
    NSDateFormatter *format = [[NSDateFormatter alloc]init];
    [format setDateFormat:formatStr];
    return [format stringFromDate:date];
}
//获取当前屏幕显示的viewcontroller
+ (UIViewController *)getCurrentVC
{
    UIViewController *result = nil;
    
    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    if (window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows)
        {
            if (tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    
    if ([nextResponder isKindOfClass:[UIViewController class]])
        result = nextResponder;
    else
        result = window.rootViewController;
    
    return result;
}

//计算已知时间和当前时间戳的差值
+ (double)intervalSinceNowWithinterval: (NSString *) theDate{
    NSDateFormatter *date=[[NSDateFormatter alloc] init];
    [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *d=[date dateFromString:theDate];
    NSTimeInterval late=[d timeIntervalSince1970]*1;
    
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval now=[dat timeIntervalSince1970]*1;
    return now-late;
}

//计算已知时间和当前时间的差值
+ (NSString*)intervalSinceNow: (NSString *) theDate
{
    
    NSDateFormatter *date=[[NSDateFormatter alloc] init];
    [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *d=[date dateFromString:theDate];
    
    NSTimeInterval late=[d timeIntervalSince1970]*1;
    
    
    NSDate* dat = [NSDate dateWithTimeIntervalSinceNow:0];
    NSTimeInterval now=[dat timeIntervalSince1970]*1;
    NSString *timeString=@"";
    
    NSTimeInterval cha=now-late;
    
    if (cha/3600<1) {
        timeString = [NSString stringWithFormat:@"%f", cha/60];
        timeString = [timeString substringToIndex:timeString.length-7];
        timeString=[NSString stringWithFormat:@"%@分钟前", timeString];
        
    }
    if (cha/3600>1&&cha/86400<1) {
        timeString = [NSString stringWithFormat:@"%f", cha/3600];
        timeString = [timeString substringToIndex:timeString.length-7];
        timeString=[NSString stringWithFormat:@"%@小时前", timeString];
    }
    if (cha/86400>1)
    {
        timeString = [NSString stringWithFormat:@"%f", cha/86400];
        timeString = [timeString substringToIndex:timeString.length-7];
        timeString=[NSString stringWithFormat:@"%@天前", timeString];
        
    }
//
    return timeString;
}


@end
